<?
include "include/config.php";
	
$tip=array ('1'=>'Garsoniera','2'=>'Apartament 2 camere','3'=>'Apartament 3 camere','4'=>'Apartament 4 camere','5'=>'Teren','6'=>'Spatiu Comercial','7'=>'Casa/Vila');
$oferta=array ('1'=>'Vanzare','2'=>'Inchiriere');
$smarty->assign('tip',$tip);
$smarty->assign('oferta',$oferta);
$valuta=array ('0'=>'Discutabil','1'=>'RON','2'=>'EURO','3'=>'USD'); 
 $smarty->assign('valuta',$valuta); 
	

$primire=$_REQUEST["o"]; 
if (isset($primire)) 
{ 	
		$N = addslashes($_POST["nume"]);
		$T = addslashes($_POST["telefon"]);
		$M = addslashes($_POST["mesaj"]); 
		$YM = addslashes($_POST["email"]);
			
		 if (strlen($N)>3) $bineN = 1 ; else {$bineN=0; $eroare="Completati Numele";}     
		 if ((isset($T)) AND (is_numeric($T))) $bineT = 1 ; else  {$bineT=0;     $eroare="Completati Numarul de Telefonul";}	
		 if (strlen($M)>3) $bineM = 1 ; else { $bineM=0; $eroare="Completati Casuta de Mesaje";}    ;     
          		  
	 $rezultat = $bineN*$bineT*$bineM;
     
    $errors=0;
    
    $number = $_POST['number'];
    if(md5($number) != $_SESSION['image_value'])
    $eroare= 'Cod gresit !';
	 
	 $dosar=$_SESSION['dosar'];
	 if ($dosar!='')
	 	{
		$dosar=implode(",",$dosar);
		$dosar='TM'.$dosar;
		$dosar=str_replace(",",", TM",$dosar);
		}
	 
	 if (($rezultat==1)AND($dosar!='')AND ($eroare=='')) 
		{ 
			
            $introdu = " <strong>Nume :</strong>".$N." <strong>Telefon : </strong> ".$T." <strong><br>Mesaj : </strong>".$M." <strong> <br> Email : </strong>".$YM." <br> Oferte :".$dosar; 
			
            mysql_query( "INSERT INTO mesaje ( nume ,descriere, data,telefon ,email,comentarii,mesaj,tip_mesaj) VALUES ('".$N."', '".$introdu."',date(NOW()),'".$T."','".$YM."','','<b>".$dosar."</b> ".$M."','5')" ) or die ('problem');  
            
			$result = MYSQL_QUERY($sqlQuery);
			unset($_SESSION['dosar']);
			$smarty->assign ('trimis',1);
		
		//se creeaza un e-mail de alerta si se trimit datele. 
		$to ="office@timonatrust.ro" . " ,";
		$to .="dan@timonatrust.ro";
       			// $to="orionsky30@gmail.com";
		$subiect = "DOSAR!";
		$mesaj= '<html>
					<head><title>Cererea Ta!</title></head>
				<body>
					<b><font color="#333333" face="tahoma">'.$N.'</font><b><br>
					<font color="#999900">'.$introdu.'</font><br><br><br><br>
					<div align="center">This is a messaage from http://www.timona.ro</div>
				</body>					
				</html>';
		$headers = "MIME-Version: 1.0\n";
		$headers .= 'Content-type: text/html; charset=iso-8859-1' ."r\n";
		$headers .= "From: ".$N." <".$YM.">\n";
		@mail($to, $subiect, $mesaj, $headers);

		}   
}

if ($_GET['sterge']!='')
$sterge[]=$_GET['sterge'];

$dosar=$_SESSION['dosar'];
if (($dosar!='')and($sterge!=''))
{
$dosar=array_diff($dosar,$sterge);
$_SESSION['dosar']=$dosar;
}

$dosar=$_SESSION['dosar'];

if ($dosar!='')
{
$dosar=array_unique($dosar);
foreach ($dosar as $element)
	{
	$_query = mysql_query("select oferta.*,locatii.name,parent.name as parent from oferta left join locatii on oferta.id_loc=locatii.id left join locatii as parent on parent.id=locatii.id_parent where oferta.id='".$element."' " );
   while ($cereri_array=mysql_fetch_array($_query))
	$_data[]=$cereri_array;
	}
}

$smarty->assign('oferte',$_data);
$smarty->assign ('eroare',$eroare);

$smarty->assign("content", $smarty->fetch(tmpd.'dosar'.tmpl_ext));
include "include/make_page.php";
?>
